<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//权限组管理
class Privgroup extends CommonController {

	function __construct(){
		
		parent::__construct();
		$this->load->model('Index/PrivgroupModel','CurModel');
		
	}
	
	
	//start
	/**
	* @name 获取列表
	* @param page ture char 页面
	* @param size ture char 数量
	* @return 成功返回1
	*/
	//end
	function get_list(){
		$user_id = $this->user_id;
		
		$filter = array('keyword','is_enable');
		$arr = array(
			'filter'=>$filter
		);
		
		$result = parent::_get_list($arr);
		if(!$result){
			$this->err_out($this->getError());
		}

		
		$this->data_out($result);
	}
	
	function info_out($info){
		
		$info['addtime'] = date('Y-m-d H:i',$info['addtime']);
		$ids = explode(',',$info['ids']);
		$info['num'] = count($ids);
		
		
		
		return $info;
	}
	
	//start
	/**
	* @name 获取信息
	* @param id ture char ID
	* @return 成功返回1
	*/
	//end
	function get_info(){
		$user_id = $this->user_id;
		
		$result = parent::_get_info();
		if(!$result){
			$this->err_out($this->getError());
		}
		
		$this->load->model('User/companyModel','companyModel');
		$result['query_list'] = $this->companyModel->ids_get($result['querys']);
		$result['action_list'] = $this->companyModel->ids_get($result['actions']);
		
		$this->data_out($result);
	}
	
	//start
	/**
	* @name 获取信息
	* @param id ture char ID
	* @return 成功返回1
	*/
	//end
	function save(){
		$user_id = $this->user_id;
		
		$filter = array(
			'name'=>'名称不能为空',
			//'ids'=>'请选择组员'
		);
		$post = array('name','info','is_enable');
		$farr = array(
			'post'=>$post,
			'filter'=>$filter
		);
		
		$ids = $this->input->post('ids',null,array());
		
		if(!is_array($ids)){
			$ids = explode(',',$ids);
		}
		$ls_ids = array();
		foreach($ids as $val){
			if(!empty($val)){
				$ls_ids[] = $val;
			}
		}
		
		
		$ids = array_unique($ls_ids);
		if(count($ids)<=0){
			$this->err_out('请选择组员');
		}
		$ids = implode(',',$ids);
		
		$time = time();
		$arr = array(
			'addtime'=>$time,
			'ids'=>$ids,
			'user_id'=>$user_id
		);
		$result = parent::_save($farr,$arr,true);
		if(!$result){
			$this->err_out($this->getError());
		}

		
		$this->add_log("保存【{$result['id']}】信息",'priv');
		
		$this->data_out($result);
	}
	


	
	//start
	/**
	* @name 删除
	* @param id ture int ID
	* @return 成功返回1
	*/
	//end
	function del(){
		
		$result = parent::_del();
		if(!$result){
			$this->err_out($this->getError());
		}
		
		
		$this->add_log("删除【{$result}】信息",'priv');
		$this->data_out($result);
		
	}
	
	//start
	/**
	* @name 设置是否启用
	* @param id ture int ID
	* @param status ture int 状态
	* @return 成功返回1
	*/
	//end
	function set_enable(){
		$id = $this->input->post('id',null,0);
		$status = $this->input->post('status',null,0);
		$info = $this->CurModel->get_info($id);
		if(!$info){
			$this->err_out('数据不存在');
		}
		
		$this->CurModel->edit(array('is_enable'=>$status),"id ='{$id}'");
		$this->add_log("修改状态信息【{$id}】",'priv');
		$this->data_out(1);
	}
	
}
